package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.LeaderDao;
import ysq.xyg.model.Leader;
import ysq.xyg.service.LeaderService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分销级别
 *
 * @author congcong tao
 * @date 2018/11/27 14:20
 */
@Service("leaderService")
public class LeaderServiceImpl extends BaseServiceImpl<Leader> implements LeaderService {

    @Resource
    private LeaderDao leaderDao;
    @Autowired
    public void setLeaderDao(LeaderDao leaderDao) {
        this.baseDao = leaderDao;
    }

    @Override
    public PageInfo<Leader> pageInfo(Leader leader, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        // 通用Example查询
        Example example = new Example(Leader.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(leader.getName())) {
            criteria.andLike("name", "%" + leader.getName() + "%");
        }
        List<Leader> list = leaderDao.selectByExample(example);
        return new PageInfo<Leader>(list);
    }
    @Override
    public PageInfo<Leader> pageLeft(Leader leader, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        List<Leader> list = leaderDao.listLeft(leader);
        return new PageInfo<Leader>(list);
    }
    @Override
    public List<Leader> list(Leader leader) {
        // 通用Example查询
        Example example = new Example(Leader.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(leader.getName())) {
            criteria.andEqualTo("name", leader.getName().trim());
        }
        if (StringUtils.isNotEmpty(leader.getDepartmentId())) {
            criteria.andEqualTo("departmentId", leader.getDepartmentId());
        }
        example.setOrderByClause(" num asc ");
        List<Leader> list = leaderDao.selectByExample(example);
        return list;
    }
}
